package com.yxym.homework;

import java.util.Scanner;

public class Homework01 {
    public static void main(String[] args) {
        T t = new T();
        new Thread(t).start();
        T2 t2 = new T2(t);
        t2.start();
    }
}

class T implements Runnable {
    private boolean loop = true;

    @Override
    public void run() {
        while (loop) {
            //休眠
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println((int) (Math.random() * 100 + 1));//输出1-100的数
        }
    }
    public void setLoop(boolean loop){//对循环的语句进行操作
        this.loop = loop;
    }
}

@SuppressWarnings({"all"})
class T2 extends Thread{
    private T t;
    private Scanner scanner = new Scanner(System.in);//输入数据

    public T2(T t){//构造器直接传入T对象
        this.t = t;
    }

    @Override
    public void run() {
        System.out.println("输入Q结束");
        char char1 = scanner.next().charAt(0);//接收数据的输入
        if(char1 =='Q'){//判断结束得标志
            t.setLoop(false);
        }
    }
}